<template>
	<view>
		<view style="height: 20rpx;background: #f8f9fb;"></view>
		<view class="view">
			<view>头像</view>
			<image :src="userinfo.imageUrl" mode=""></image>
			<u-icon name="arrow-right" color="grey" style="margin-left: 20rpx;"></u-icon>
		</view>
		<view class="item">
			<view>用户名</view>
			<view>{{userinfo.username}}</view>
			<u-icon name="arrow-right" color="grey" style="margin-left: 20rpx;"></u-icon>
		</view>
		<view class="item">
			<view>手机号</view>
			<view>{{userinfo.mobile}}</view>
			<u-icon name="arrow-right" color="grey" style="margin-left: 20rpx;"></u-icon>
		</view>
		<view style="height: 20rpx;background: #f8f9fb;"></view>
		<view class="item">
			<view>昵称</view>
			<view>{{userinfo.nickName}}</view>
			<u-icon name="arrow-right" color="grey" style="margin-left: 20rpx;"></u-icon>
		</view>
		<view class="item">
			<view>性别</view>
			<view>男</view>
			<u-icon name="arrow-right" color="grey" style="margin-left: 20rpx;"></u-icon>
		</view>
		<view style="height: 20rpx;background: #f8f9fb;"></view>
		<button class="logout-btn" @click="logout" type="default">退出登录</button>
	</view>
</template>

<script>
	// import {mapState} from 'vuex'
	import api from '@/api/api.js'
	export default {
		data() {
			return {
				userinfo: {}
			}
		},

		onLoad() {
			this.$util.isLogin()
			this.userinfo = uni.getStorageSync('userInfo')
		},

		computed: {
			// ...mapState(['userInfo'])
		},

		methods: {
			//退出
			logout() {
				uni.showModal({
					title: '确定退出登录?',
					content: '退出后不会删除任何历史数据',
					success: async (res) => {
						if (res.confirm) {
							let a = uni.getStorageSync("mxgEducationToken")
							const {
								code,
								message
							} = await api.logout(a)
							if (code === 20000) {
								//退出成功
								this.$util.msg('成功退出登录')
								this.$store.commit('logout')
								setTimeout(() => {
									uni.navigateBack({
										delta: 1
									})
								}, 300)
							} else {
								this.$util.msg(message)
							}
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.view {
		display: flex;
		align-items: center;
		padding: 0 40rpx;
		height: 170rpx;
		box-sizing: border-box;
		border-bottom: 2rpx solid #f8f9fb;

		:nth-child(1) {
			flex: 1;
		}

		image {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
			margin: 0 20rpx;
		}
	}

	.item {
		display: flex;
		align-items: center;
		padding: 0 40rpx;
		height: 100rpx;
		box-sizing: border-box;
		border-bottom: 2rpx solid #f8f9fb;
		color: grey;

		:nth-child(1) {
			flex: 1;
			color: black;
		}
	}
	.logout-btn{
		background: white;
	}
</style>
